# 选课
from tortoise.models import Model # 这个基类是所有数据模型类的基础
from tortoise import fields

# Model 使自定义模型类能够和数据库表建立映射关系
# 内治疗数据的增删改查（CRUD）
# 通过继承 Model 基类，Student 类就具备了与数据库交互的能力，无需手动编写 SQL 即可实现对 Student 表的数据操作。
# 学生
class Student(Model):
    id = fields.IntField(pk=True) # 整型  pk=True主键
    name = fields.CharField(max_length=20,description="姓名")
    pwd = fields.CharField(max_length=32,description="密码")
    age = fields.IntField(description="年龄")
    sex = fields.CharField(max_length=10,description="性别")
    sno = fields.IntField(description="学号")

    #一对多的关系
    clas= fields.ForeignKeyField("models.Clas",related_name="students")

    # 多对多
    courses = fields.ManyToManyField("models.Course",related_name="students")



# 课程
class Course(Model):
    id = fields.IntField(pk=True)
    name = fields.CharField(max_length=20,description="课程名称")
    teacher = fields.ForeignKeyField("models.Teacher",related_name="courses")
    addr = fields.CharField(max_length=20,description="教室地址",default="")


class Teacher(Model):
    id = fields.IntField(pk=True)
    name = fields.CharField(max_length=20,description="姓名")
    pwd = fields.IntField(max_length=32,description="密码")
    tno = fields.IntField(description="工号")


# 班级
class Clas(Model):
    name = fields.CharField(max_length=20,description="班级名称")



